import { Army } from "./Army";
import { totoalArmyInfo } from "./totoalArmyInfo";

/**
 * 侦查信息结构体
 */
export class reportInfo_Invest {
    /**
     * 攻击方军队
     */
    attackArmy: Army;
    /**
     * 损失的攻击方军队
     */
    lostAttackArmy: Army;
    /**
     * 对方资源情况
     */
    wood: number;
    mud: number;
    iron: number;
    food: number;
    /**
     * 防守方军队
     */
    defenseArmy: Army;
    /**
     * 损失的防守方军队
     */
    lostDefenseArmy: Army;
    /**
     * 协防部队
     */
    helpArmy: Army[] = [];
    /**
     * 损失的协防部队
     */
    lostHelpArmy: Army[] = [];
    /**
     * 汇总的协防军队 totoalArmyInfo
     */
    totalHelpArmy: totoalArmyInfo;
    /**
     * 汇总的协防军队损失 totoalArmyInfo
     */
    totalLostHelpArmy: totoalArmyInfo;

    /**
     * 构造函数
     * @param {report} rp
     */
    constructor(rp) {
        /* 侦查报告结构：攻击士兵串|攻击损失串@防御士兵串|防御损失串[@协防士兵|协防损失[*协防士兵|协防损失]] */
        let pList = rp.rParam.trim().split('@');
        if (pList.length >= 1) {
            //pList[0],攻击方信息，包括攻击部队、损失部队
            let attackInfo = pList[0].split('|');
            this.attackArmy = Army.createArmyBySoldiersString(attackInfo[0])

            this.lostAttackArmy = Army.createArmyBySoldiersString(attackInfo[1])

        }
        if (pList.length >= 2) {
            //pList[1],防守方信息，包括防守部队、损失部队
            let defenseInfo = pList[1].split('|');
            this.defenseArmy = Army.createArmyBySoldiersString(defenseInfo[0])
            this.lostDefenseArmy = Army.createArmyBySoldiersString(defenseInfo[1])
        }
        if (pList.length >= 3) {
            //pList[2],协防方信息，包括协防部队、损失部队
            let helpInfo = pList[2].split('*');
            for (let i = 0; i < helpInfo.length; i++) {
                let detail = helpInfo[i].split('|');
                let tmpArmy = Army.createArmyBySoldiersString(detail[0])
                this.helpArmy.push(tmpArmy);
                tmpArmy = Army.createArmyBySoldiersString(detail[1])
                this.lostHelpArmy.push(tmpArmy);
            }
        }
        this.totalHelpArmy = new totoalArmyInfo();
        this.totalLostHelpArmy = new totoalArmyInfo();
        for (let j = 0; j < this.helpArmy.length; j++) {
            let a = this.helpArmy[j]
            for (let i = 0; i < a.soldierList.length; i++) {
                let so = a.soldierList[i]
                this.totalHelpArmy.sList[so.id - 1].count += so.count
            }

        }
        for (let j = 0; j < this.lostHelpArmy.length; j++) {
            let a = this.lostHelpArmy[j]
            for (let i = 0; i < a.soldierList.length; i++) {
                let so = a.soldierList[i]
                if(so.id == 0){
                    continue
                }
                this.totalLostHelpArmy.sList[so.id - 1].count += so.count

            }

        }
    }
}
